#ifndef __PR2000_DRVCOMMON_H__
#define __PR2000_DRVCOMMON_H__

#include "pr2000_support.h"
#include "typedef.h"
#if defined(__HOST_LINUX_SYSTEM__)

/* __KERNEL__ */
#ifdef __KERNEL__
#else
#include <stdint.h>
#endif /* __KERNEL__ */

#define PR2000_MAJOR	(241)
static const uint8_t strDevName[4][10] = {
	"pr2000_0",
	"pr2000_1",
	"pr2000_2",
	"pr2000_3"
};

#elif defined(__HOST_MICOM_SYSTEM__)


#endif //defined(__HOST_LINUX_SYSTEM__)
/************************************************************/
/*                   App & Driver common 		    */
/************************************************************/
enum {
	NTSC = 0,
	PAL,
	MAX_VIDEO_SYSTEM_TYPE
};

/***************************************************************************************************************/
/* error module */
typedef enum {
	PR_ERR_COMMON = 0x01,
	PR_ERR_VDEC = 0x02,
	PR_ERR_UTC = 0x03,
	PR_ERR_OSG = 0x04,

	MAX_PR_ERR_MODULE
}PR_ERR_MODULE_E;
/* error code */
typedef enum {
	/* common */
	PR_ERR_HANDLE = 0x001,
	PR_ERR_INVALID_DRVFD = 0x002,
	PR_ERR_ILLEGAL_PARAM = 0x003,
	PR_ERR_EXIST = 0x004,
	PR_ERR_UNEXIST = 0x005,
	PR_ERR_NULL_PTR = 0x006,
	PR_ERR_NOT_PERM = 0x007,
	PR_ERR_NOT_SUPPORT = 0x008,
	PR_ERR_NOT_CONFIG = 0x009,
	PR_ERR_NO_MEM = 0x00A,
	PR_ERR_NO_BUF = 0x00B,
	PR_ERR_FULL_BUF = 0x00C,
	PR_ERR_EMPTY_BUF = 0x00D,
	PR_ERR_NOT_READY = 0x00E,
	PR_ERR_BUSY = 0x00F,
	PR_ERR_INVALID_DEVID = 0x010,
	PR_ERR_INVALID_CHNID = 0x011,
	PR_ERR_LOCK = 0x012,
	PR_ERR_UNLOCK = 0x013,
	PR_ERR_PUT_QUEUE = 0x014,
	PR_ERR_GET_QUEUE = 0x015,

	MAX_PR_ERR_CODE
}PR_ERR_CODE_E;

static const uint8_t strDevDrvName[10] = {"pr2000"};

/* error code */
#define PR_ERROR_CODE_TYPE_APP	(0x0)
#define PR_ERROR_CODE_TYPE_LIB	(0x1)
#define PR_ERROR_CODE_TYPE_DRV	(0x2)

#define PR_ERROR_CODE(type, module, code)	(0xF000F000|((type&0xF)<<24)|((module&0xFF)<<16)|((code)&0xFFF))
#define PR_ERROR_CODE_APP(module, code)		PR_ERROR_CODE(PR_ERROR_CODE_TYPE_APP, module, code)
#define PR_ERROR_CODE_LIB(module, code)		PR_ERROR_CODE(PR_ERROR_CODE_TYPE_LIB, module, code)
#define PR_ERROR_CODE_DRV(module, code)		PR_ERROR_CODE(PR_ERROR_CODE_TYPE_DRV, module, code)
/***************************************************************************************************************/

/********************************************************************/
/*				app & drv common struct								*/
/********************************************************************/
typedef struct
{
	uint8_t i2cSlvAddr;
	uint8_t vinMode;
	uint8_t vidOutMode;
	uint8_t bCascade;
	uint8_t bCascadeMux;
	uint8_t chid_num;
	uint8_t bBt656;
	uint8_t datarate;
	uint8_t clkphase_Mux;
	uint8_t clkphase_148Mhz;
	uint8_t clkphase_74Mhz;
	uint8_t clkphase_36Mhz;
	uint8_t clkphase_27Mhz;
}_stAttrChip;

typedef struct
{
	uint8_t u8SlvAddr;
	uint8_t u8Page;
	uint8_t u8Reg;
	uint8_t u8Mask;
	uint8_t u8Data;
}_stPrReg;

#ifdef SUPPORT_VID
typedef struct
{
	uint16_t u16HActive; //b[12:0]
	uint16_t u16HDelay; //b[12:0]
	uint16_t u16VActive; //b[10:0]
	uint16_t u16VDelay; //b[10:0]
	uint16_t u16HSCLRatio; //b[15:0] 0:skip write
}_stChnAttr;

typedef struct
{
	uint8_t u8CbGain;
	uint8_t u8CrGain;
	uint8_t u8CbOffset;
	uint8_t u8CrOffset;
}_stCscAttr;

typedef struct
{
	uint8_t u8Contrast;
}_stContrast;

typedef struct
{
	uint8_t u8Bright;
}_stBright;

typedef struct
{
	uint8_t u8Saturation;
}_stSaturation;

typedef struct
{
	uint8_t u8Hue;
}_stHue;

typedef struct
{
	uint8_t u8Sharpness; //b[3:0]
}_stSharpness;
#endif // SUPPORT_VID

#ifdef SUPPORT_UTC
#define MAX_PR2000_UTC_BUF_SIZE           (64)
typedef struct
{
        uint8_t utcCmd[MAX_PR2000_UTC_BUF_SIZE];
        uint8_t utcCmdLength;
}_stUTCCmd;
#endif // SUPPORT_UTC

#ifdef SUPPORT_CEQ
typedef struct
{
        uint8_t stepBits[20]; //bit0~bit159
}_stCEQInfo;

#endif // SUPPORT_CEQ
#define SET_STEP_BIT(nr, pBits) (pBits[nr/8] |= 1<<(nr%8))
#define TEST_STEP_BIT(nr, pBits) ((pBits[nr/8]>>(nr%8)) & 1)


#ifdef SUPPORT_OSG
typedef struct
{
        uint32_t addr;
        uint16_t size;
        uint8_t *pBuf;
}_stOSGBuf;

typedef struct
{
        uint32_t oddAddr;
        uint32_t evenAddr;
}_stOSGRLELoc;

typedef struct
{
        uint8_t bEnable;
        uint32_t addr;
}_stOSGDisplay;

#endif // SUPPORT_OSG


/********************************************************************/
/*		ioctl command define		*/
/********************************************************************/
/* Use 'I' as magic number */
#define PR_IOC_MAGIC  'I'
#define PR_IOC_MAXNR  255

#define PR_IOC_RESET    			_IO(PR_IOC_MAGIC, (0x00))
#define PR_IOG_CHIPATTR				_IO(PR_IOC_MAGIC, (0x01))
#define PR_IOS_CHIPATTR				_IO(PR_IOC_MAGIC, (0x02))

#define PR_IOS_REGWRITE  			_IO(PR_IOC_MAGIC, (0x10))
#define PR_IOG_REGREAD  			_IO(PR_IOC_MAGIC, (0x11))
#define PR_IOS_REGMASKWRITE  			_IO(PR_IOC_MAGIC, (0x12))
#define PR_IOG_QUERY_WQPOLL  			_IO(PR_IOC_MAGIC, (0x13))

#define PR_IOS_RXMODE  				_IO(PR_IOC_MAGIC, (0x14))
#define PR_IOG_RXMODE  				_IO(PR_IOC_MAGIC, (0x15))
#define PR_IOS_CLKPHASE 			_IO(PR_IOC_MAGIC, (0x16))

#define PR_IOG_NOVID_STATUS  			_IO(PR_IOC_MAGIC, (0x17))
#define PR_IOS_PRINT_MKTBL  			_IO(PR_IOC_MAGIC, (0x18))

#define PR_IOG_CEQPROCINFO			_IO(PR_IOC_MAGIC, (0x19))

#define PR_IOS_VID_CHNATTR  			_IO(PR_IOC_MAGIC, (0x20))
#define PR_IOG_VID_CHNATTR  			_IO(PR_IOC_MAGIC, (0x21))
#define PR_IOS_VID_CSCATTR  			_IO(PR_IOC_MAGIC, (0x22))
#define PR_IOG_VID_CSCATTR  			_IO(PR_IOC_MAGIC, (0x23))
#define PR_IOS_VID_CONTRAST  			_IO(PR_IOC_MAGIC, (0x24))
#define PR_IOG_VID_CONTRAST  			_IO(PR_IOC_MAGIC, (0x25))
#define PR_IOS_VID_BRIGHT  			_IO(PR_IOC_MAGIC, (0x26))
#define PR_IOG_VID_BRIGHT  			_IO(PR_IOC_MAGIC, (0x27))
#define PR_IOS_VID_SATURATION  			_IO(PR_IOC_MAGIC, (0x28))
#define PR_IOG_VID_SATURATION  			_IO(PR_IOC_MAGIC, (0x29))
#define PR_IOS_VID_HUE  			_IO(PR_IOC_MAGIC, (0x2A))
#define PR_IOG_VID_HUE  			_IO(PR_IOC_MAGIC, (0x2B))
#define PR_IOS_VID_SHARPNESS  			_IO(PR_IOC_MAGIC, (0x2C))
#define PR_IOG_VID_SHARPNESS  			_IO(PR_IOC_MAGIC, (0x2D))

#define PR_IOS_UTC_START_RX			_IO(PR_IOC_MAGIC, (0x31))
#define PR_IOS_UTC_START_TX			_IO(PR_IOC_MAGIC, (0x32))
#define PR_IOS_UTC_SEND_TXDATA			_IO(PR_IOC_MAGIC, (0x33))
#define PR_IOG_UTC_RECV_SIZE                    _IO(PR_IOC_MAGIC, (0x34))
#define PR_IOG_UTC_RECV_RXDATA                  _IO(PR_IOC_MAGIC, (0x35))
#define PR_IOS_UTC_HDT_CHGOLD_CMD		_IO(PR_IOC_MAGIC, (0x39))

#define PR_IOS_OSG_WRITE			_IO(PR_IOC_MAGIC, (0x50))
#define PR_IOS_OSG_READ				_IO(PR_IOC_MAGIC, (0x51))
#define PR_IOS_OSG_ERASE			_IO(PR_IOC_MAGIC, (0x52))
#define PR_IOS_OSG_SETLUTLOC			_IO(PR_IOC_MAGIC, (0x53))
#define PR_IOS_OSG_SETRLELOC			_IO(PR_IOC_MAGIC, (0x54))
#define PR_IOS_OSG_DISPLAY			_IO(PR_IOC_MAGIC, (0x55))


#endif /* __PR2000_DRVCOMMON_H__ */
